package com.hs.controller;

import com.hs.entity.User;
import com.hs.service.LoginService;
import com.hs.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author fuyanru
 * @date 2024年05月02日 1:25
 */
@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;
    //登录
    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user){
        return loginService.login(user);
    }
    //退出登录
    @RequestMapping("/user/logout")
    public ResponseResult logout(){
        return loginService.logout();
    }


    @RequestMapping("/hello")
    @PreAuthorize("@ex.hasAuthority('system:test:list')")// 用户必须具备test权限才可以访问该方法
//    @PreAuthorize("hasAnyAuthority('admin','system:test:list')")
//    @PreAuthorize("hasRole('system:test:list')")
//    @PreAuthorize("hasAnyRole('admin','system:test:list')")
    public String hello(){
        return "hello";
    }
    @RequestMapping("/testCors")
    public ResponseResult testCors(){
        return new ResponseResult<>(200,"testCors，测试成功！");
    }
}
